'use strict';

import * as actions from '../../actions/ring_tags_step3';

// 对页面prop 数据进行管理
const initialState = {
  creating: false,
  error:false,
  loginError:false,
  message:"",
  zType:"decreaseAmount",
  totalResults:0,
  items:[],
  page:1,
  pagesize:10,
  cids:"",
  q:"",
  setItems:[],
  sellerCats:[]
};
const defaultAction = {
  type: 'doNothing'
};

export default function index(state = initialState, action = defaultAction ) {
  switch (action.type) {
    case actions.CLOSE_DIALOG:
      return Object.assign({}, state, {
		error:action.visible,
        loginError:false
      });
	  break;
    case actions.LOAD_ERR:
      return Object.assign({}, state, {
        creating:false,
		error:true,
		loginError:action.loginFalse,
		message:action.message
      });
	  break;
    case actions.SHOW_creating:
      return Object.assign({}, state, {
        creating:action.creating
      });
	  break;
    case actions.SET_ITEMS:
	  state.setItems[action.itemset.num_iid]={...action.itemset};
      return Object.assign({}, state, {});
	  break;
    case actions.GET_ITEMS_ON_SEAL:
      return Object.assign({}, state, {
		creating:false,
		error:false,
		loginError:false,
        items:action.items,
        totalResults:action.total_results,
		page:action.page,
		pagesize:action.pagesize,
		cids:action.cids,
		q:action.q
      });
	  break;
    case actions.GET_ITEMS_IN_DEPOT:
      return Object.assign({}, state, {
		creating:false,
		error:false,
		loginError:false,
        items:action.items,
        totalResults:action.total_results,
		page:action.page,
		pagesize:action.pagesize,
		cids:action.cids,
		q:action.q
      });
	  break;
    case actions.LOAD_SET_ITEMS_IN_DATABASE:
		return Object.assign({}, state, {
			setItems:action.itemset
		});
	  break;
    case actions.GET_SELLER_CATS:
	  return Object.assign({}, state, {sellerCats:action.seller_cats});
	  break;
    case actions.ADD_ITEM_TO_ACTIVE:
	  state.setItems[action.newItemSet.num_iid]=action.newItemSet;
      return Object.assign({}, state, {
		creating:false,
		error:false,
		loginError:false,
		editItemIid:action.newItemSet.num_iid
      });
	  break;
    default:
      return state;
  }
}